/**
* @Title: warning_ctrl.js
* @Description: TODO
* Copyright: Copyright (c) 2014 
 * Company:中国平安
*  预警查询
* @Project HIMS-FWA
* @date 2014年10月27日 下午4:43:38
* @version V1.0
*/
;
(function(){
	'use strict';
	
	var app = angular.module('fwa.mainApp');
	app.controller('WarningIntegrityQuery', ['$scope','$stateParams','FwaTabsetService','$modal','BaseURL','Modal','WarningService',
	                                function($scope,$stateParams,FwaTabsetService,$modal,baseUrl,Modal,WarningService){
		$scope.warningService = WarningService;
		WarningService.initMedicalOrgInfoList();
		WarningService.getActinstList();//事件状态
		$scope.form = {};
		$scope.form.warnDate = {};
		var doctorCode = $stateParams.doctorCode || WarningService.doctorCode;
		var warnType = $stateParams.warnType || WarningService.warnType;
		var startDateUrl = $stateParams.startDate || WarningService.startDate;
		var endDateUrl = $stateParams.endDate || WarningService.endDate;
		WarningService.doctorCode = doctorCode;
		WarningService.warnType = warnType;
		WarningService.startDateUrl = startDateUrl;
		WarningService.endDateUrl = endDateUrl;
		var cellTemplate = 
			'<td>'+
				'<a title=\'{{data.warnNoBiz}}\' ng-click="clickLink(\'integrityJump.warningViewWarn\',data)"">{{data.warnNoBiz}}</a>'+
			'</td>',
			indexNo = '<td>'+
				'{{$index+1}}'+
			'</td>';
       $scope.columns = [
        {label:'预警编号',width:'10%',cellClass:'text-left', cellTemplate:cellTemplate},
        {label:'预警事件名称',map:'summary',width:'12%'},
        {label:'机构名称',map:'medicalOrgName',width:'12%'},
        {label:'处理方式',map:'process',width:'8%'},
        {label:'预警时段',map:'happenDate',width:'14%'},
        {label:'反馈截止时间',map:'feedbackEndDate',width:'9%'},
        {label:'受理时间',map:'warnDate',width:'9%'},
        {label:'审核时间',map:'auditDate',width:'9%'},
        {label:'事件状态',map:'actName',width:'10%'},
        {label:'经办人',map:'agent',width:'9%'}
    ];
       $scope.clickLink = function (url,data){
    	   FwaTabsetService.selectTab(url,{warnNo:data.warnNo,actNo:data.actNo,processNo:data.processNo},false);
       }
		//分页配置
       $scope.current = {
    		   totalCount: 0,
    		   currentPage: 0,
    		   limit: 20
       };       
       
		//分页监听
        $scope.$on('pageTool.skipPage',function(e,v) {
            $scope.current.currentPage = v;
            query();
        });

        //查询
        function query() {
        	var start = 0;
        	var startDate = '';
			if ($scope.form.warnDate 
			  && $scope.form.warnDate.start) {
				startDate = $scope.form.warnDate.start;
			}else{
				startDate=startDateUrl;
			}
			var endDate = '';
			if ($scope.form.warnDate
				&&$scope.form.warnDate.end) {
				endDate = $scope.form.warnDate.end;
			}else{
				endDate=endDateUrl;
			}
			
			if(parseInt( $scope.current.currentPage) > 1){
                  start = (parseInt( $scope.current.currentPage) - 1) *  $scope.current.limit;
            }
			
			var params = {
					warnNoBiz: $scope.form.warnNoBiz,
					medicalOrgCode: $scope.form.medicalOrgCode,
					summary:$scope.form.summary,
					feedbackEndDate:$scope.form.feedbackEndDate,
					actNo:$scope.form.actNo,
					startDate:startDate,
					endDate:endDate,
					start:start,
					limit:$scope.current.limit,
					agentName:$scope.form.agentName,
					doctorCode:doctorCode,
					warnType:warnType
			};
        	WarningService.query(params).success(function(res){
                $scope.tableData = res.result;
                $scope.current.totalCount = res.total;
            });
        }
        
        //页面点击查询事件
        $scope.onSubmit = function(){
        	$scope.current.currentPage = 1;
        	query();
        };
        //初始化加载数据
        $scope.onSubmit();
        
         //重置
        $scope.resetBut = function(){
			$scope.form = {};
			$scope.form.warnDate = {};
			$scope.onSubmit();
		}
	}]);
})();